package logic

import (
	"context"
	"major-six/major/order/internal/models"

	"major-six/major/order/internal/svc"
	"major-six/major/order/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderUpdateLogic {
	return &OrderUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderUpdateLogic) OrderUpdate(in *order.OrderUpdateRequest) (*order.OrderUpdateResponse, error) {
	mod := models.NewOrderModel(l.ctx, l.svcCtx)
	orderInfo, err := mod.Update(int(in.Id), int(in.Status))
	if err != nil {
		return nil, err
	}

	return &order.OrderUpdateResponse{UpdateInfo: orderInfo}, nil
}
